package com.zzg.datastructure.tree;

import com.zzg.datastructure.tree.binarytree.BinaryTree;
import com.zzg.datastructure.tree.entity.HeroNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author zhengzg
 * @Date 2022-09-16
 * @Version v1.0
 * 二叉树遍历
 */
public class BinaryTreeDemo {

    public static void main(String[] args) {
        String[] hero = {"宋江", "卢俊义", "吴用", "林冲", "关胜","ceshi"};
        List<HeroNode> heroList = new ArrayList<>();

        // 首先创建一个满二叉树
        BinaryTree binaryTree = new BinaryTree();
        // 创建需要的节点
        for (int i = 0; i < hero.length; i++) {
            heroList.add(new HeroNode(i + 1,hero[i]));
        }

        heroList.get(0).setLeft(heroList.get(1));
        heroList.get(0).setRight(heroList.get(2));
        heroList.get(2).setLeft(heroList.get(3));
        heroList.get(2).setRight(heroList.get(4));
        heroList.get(4).setLeft(heroList.get(5));
        binaryTree.setRoot(heroList.get(0));

        // 测试删除
        binaryTree.delNode(5);

        // 前序遍历
        binaryTree.preOrder();
//
//        // 中序遍历
//        binaryTree.infixOrder();
//
//        // 后序遍历
//        binaryTree.postOrder();

        //binaryTree.postOrderSearch(1);


    }
}
